/*! firegy.js
* The MIT License (MIT)
 * Copyright (c) 2018 为挨批
 * 
 * Permission is hereby granted, free of charge, to any person obtaining a copy of
 * this software and associated documentation files (the "Software"), to deal in
 * the Software without restriction, including without limitation the rights to
 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
 * the Software, and to permit persons to whom the Software is furnished to do so,
 * subject to the following conditions:
 * 
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
(function($){
	/*
	 * 以下对jquery元素集扩展 
	 */
	$.fn.extend({
		/*
         * Jquery中扩展复选框或者单选钮选中
		 */
		check:function(){
			return this.each(function() {
				this.checked = true;
			});
		},
		//扩展复选框单选钮取消选中
		uncheck:function(){
			return this.each(function(){
				this.checkd = false;
			});
		},
		//禁用按钮
		disable:function(){
			this.attr("disabled",true);
		},
		//启用按钮
		enable:function(){
			this.attr("disabled",false);
		}
	})

	/*
	 * 以下对jquery对象本身扩展
	 */
	$.extend({
		/**
		 * 将给定的数组以"'a','b'"方式拼接
		 * @param arr 数组
		 */
		concatWithQuotMarks:function(arr){
			var resultStr="";
			if($.isArray(arr)){
				arr.forEach(function(value,index,a){
					if(!isEmpty(value)){
						if(resultStr.length>0){
							resultStr=resultStr+","+"\'"+value+"\'";
						}else{
							resultStr="\'"+value+"\'";
						}
					}
				})
			}
			return resultStr;
		},
		/**
		 * 替换字符串中所有,
		 */
		replaceAllComma:function(str){
			return str.replace(/,/g,'');
		}
	})

	function isEmpty(text){
		return text == null && text ==="" && text == undefined;
	}
})(jQuery)